import EChart from './baseECharts';
import settings from '../../config/settings';

export default class FaultLine extends EChart {
    /**
     *
     * @param {Object} data
     * title
     * titleFontSize    标题字体大小
     * titleFontColor   标题颜色
     * tipTextSize      弹出层字体大小
     */
    setData(data) {
        let list = data.list;
        let option = {
            title: {
                text: data.title || '告警平均日趋势',
                show: true,
                textStyle: {
                    fontWeight: 'normal',
                    fontSize: (data.titleFontSize || 0.3) * settings.BASE_SIZE,
                    color: data.titleFontColor || '#00A9F6'
                },
                left: '6%'
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    lineStyle: {
                        color: '#ddd'
                    }
                },
                backgroundColor: 'rgba(255,255,255,1)',
                padding: [0.05 * settings.BASE_SIZE, 0.1 * settings.BASE_SIZE],
                textStyle: {
                    color: '#7588E4',
                    fontSize: (data.tipTextSize || 0.2) * settings.BASE_SIZE
                },
                extraCssText: 'box-shadow: 0 0 5px rgba(0,0,0,0.3)'
            },
            xAxis: {
                type: 'category',
                data: list.map(t => t.timeValue),
                boundaryGap: false,
                splitLine: {
                    show: false,
                    interval: 'auto',
                    lineStyle: {
                        color: ['#D4DFF5']
                    }
                },
                axisTick: {
                    show: false
                },
                axisLine: {
                    lineStyle: {
                        color: data.titleFontColor || '#00A9F6'
                    }
                },
                axisLabel: {
                    margin: 0.1 * settings.BASE_SIZE,
                    textStyle: {
                        fontSize: (data.fontSize || 0.2) * settings.BASE_SIZE
                    }
                }
            },
            grid: {
                right: '5%'
            },
            yAxis: {
                type: 'value',
                splitLine: {
                    show: false,
                    lineStyle: {
                        color: ['#D4DFF5']
                    }
                },
                axisTick: {
                    show: false
                },
                axisLine: {
                    lineStyle: {
                        color: data.titleFontColor || '#00A9F6'
                    }
                },
                axisLabel: {
                    margin: 0.1 * settings.BASE_SIZE,
                    textStyle: {
                        fontSize: (data.fontSize || 0.2) * settings.BASE_SIZE
                    }
                }
            },
            series: [
                {
                    name: '报警',
                    type: 'line',
                    smooth: false,
                    showSymbol: false,
                    symbol: 'circle',
                    symbolSize: 6,
                    data: list.map(t => t.alarmCount),
                    areaStyle: {
                        normal: {
                            color: new EChart.echarts.graphic.LinearGradient(
                                0,
                                0,
                                0,
                                1,
                                [
                                    {
                                        offset: 0,
                                        color: 'rgba(199, 237, 250,0.5)'
                                    },
                                    {
                                        offset: 1,
                                        color: 'rgba(199, 237, 250,0.2)'
                                    }
                                ],
                                false
                            )
                        }
                    },
                    itemStyle: {
                        normal: {
                            color: '#00A9F6'
                        }
                    },
                    lineStyle: {
                        normal: {
                            width: 3
                        }
                    }
                },
                {
                    name: '处理',
                    type: 'line',
                    smooth: false,
                    showSymbol: false,
                    symbol: 'circle',
                    symbolSize: 6,
                    data: list.map(t => t.detailCount),
                    areaStyle: {
                        normal: {
                            color: new EChart.echarts.graphic.LinearGradient(
                                0,
                                0,
                                0,
                                1,
                                [
                                    {
                                        offset: 0,
                                        color: 'rgba(216, 244, 247,1)'
                                    },
                                    {
                                        offset: 1,
                                        color: 'rgba(216, 244, 247,1)'
                                    }
                                ],
                                false
                            )
                        }
                    },
                    itemStyle: {
                        normal: {
                            color: '#58c8da'
                        }
                    },
                    lineStyle: {
                        normal: {
                            width: 3
                        }
                    }
                }
            ]
        };

        this.setOption(option);
    }
}
